 
 
import cv2
imgpath = r'data\pose4\train\images\000002.jpg'
txtpath = r'data\pose4\train\labels\000002.txt'
 
f = open(txtpath,'r')
lines = f.readlines()
img = cv2.imread(imgpath)
h, w, c = img.shape
colors = [[255, 128, 0], [255, 153, 51], [255, 178, 102], [230, 230, 0], [255, 153, 255],
                                      [153, 204, 255], [255, 102, 255], [255, 51, 255], [102, 178, 255], [51, 153, 255],
                                      [255, 153, 153], [255, 102, 102], [255, 51, 51], [153, 255, 153], [102, 255, 102],
                                      [51, 255, 51], [0, 255, 0], [0, 0, 255], [255, 0, 0], [255, 255, 255]]
for line in lines:
    print(line)
    l = line.split(' ')
    print(len(l))
    print(l)
    print(l[5:])
    cx = float(l[1]) * w
    cy = float(l[2]) * h
    weight = float(l[3]) * w
    height = float(l[4]) * h
    xmin = cx - weight/2
    ymin = cy - height/2
    xmax = cx + weight/2
    ymax = cy + height/2
    print((xmin,ymin),(xmax,ymax))
    cv2.rectangle(img,(int(xmin),int(ymin)),(int(xmax),int(ymax)),(0,255,0),2)
    kpts = []
 
    for i in range(15):
        x = float(l[5:][3*i]) * w
        y = float(l[5:][3*i+1]) * h
        s = int(l[5:][3*i+2])
        print(x,y,s)
        if s != 0:
            cv2.circle(img,(int(x),int(y)),1,colors[i],2)
        kpts.append([int(x),int(y),int(s)])
    print(kpts)
    kpt_line = [[0, 2], [1, 2], [2, 14], [5, 6], [5, 14], [3, 4], [3, 14], [13, 14], [9, 8], [8, 7], [7, 13], [12, 11], [11, 10], [10, 13]]
    for j in range(len(kpt_line)):
        m,n = kpt_line[j][0],kpt_line[j][1]
        if kpts[m][2] !=0 and kpts[n][2] !=0:
            cv2.line(img,(kpts[m][0],kpts[m][1]),(kpts[n][0],kpts[n][1]),colors[j],2)
 
img = cv2.resize(img, None, fx=0.9, fy=0.9)
cv2.imshow('1',img)
cv2.waitKey(0)